Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Half of program print problem(Only half of my program is printing!)
icon8.gif  Half of program print problem [message #1708598] Thu, 17 September 2015 23:03 Go to next message
Angelica Segura is currently offline Angelica SeguraFriend
Messages: 1
Registered: September 2015
Junior Member
Hi,
I'm creating a program for class and have done everything as it's said in the book. At first I had the keyboard should never be closed problem, but after a quick email to my professor it worked. Now only half of my program will print, I really really need help, but I don't want to ask my professor because I've been bothering him all day. Embarrassed If you guys could help me before midnight central time that would be amazing, listed below is the what I have so far on the program.

import java.util.Scanner;

public class Program1Segura
{
public static void main(String[] args)
{
System.out.println("Hello out there.");
System.out.println("I will add two number for you.");
System.out.println("Enter two whole numbers on a line:");

int n1, n2;

Scanner keyboard = new Scanner(System.in);
n1 = keyboard.nextInt(35);
n2 = keyboard.nextInt(20);

System.out.println("The sum of those two numbers is");
System.out.println(n1 + n2);
keyboard.close();
}
}

Any help is greatly appreciated!!
Re: Half of program print problem [message #1708860 is a reply to message #1708598] Tue, 22 September 2015 01:11 Go to previous message
Daniel Maclam is currently offline Daniel MaclamFriend
Messages: 2
Registered: September 2015
Junior Member
I am not sure what the desired output is. Your code runs perfectly except I would make one small change. To let the user actually specify the integers to be added remove the integers from keyboard.nextint();

		System.out.println("Hello out there.");
		System.out.println("I will add two number for you.");
		System.out.println("Enter two whole numbers on a line:");

		int n1, n2;

		Scanner keyboard = new Scanner(System.in);
		n1 = keyboard.nextInt();
		n2 = keyboard.nextInt();

		System.out.println("The sum of those two numbers is");
		System.out.println(n1 + n2);
		keyboard.close();
Previous Topic:Code Template Question (Auto Generated Method Stub)
Next Topic:Eclipse Luna does not find references to Java elements
Goto Forum:
  


Current Time: Sun Sep 22 20:55:17 GMT 2024

Powered by FUDForum. Page generated in 0.08134 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top