Hi all... i need to do some study regarding how to count the multiple int that keep in by user like this :-

1
3
5
66
88

(1+3=4+5=9+66=75+88=163 - the program will terminted cause exceed than 100)

how to do ?...i stuck very long here...below is the coding that i make;;hope u will help me;;;

``````import java.io.*;
import java.util.Scanner;

public class Soalan1
{
public static void main ( String [] args ) throws IOException   //throw any exceptions
{

//note the previous line. you can write the statements 2 and 3 in a single line
// 2&3. Create a single shared BufferedReader for keyboard input.
int a,n, sum;

sum = 0;

System.out.println( "KEEP IN THE INTEGER ! " );
while (true)
{

Scanner scan = new Scanner(System.in);

n = scan.nextInt();
sum = sum + n;

if (sum  >= 100)
{

// n is zero, so break out of the enclosing while loop
break;

}//end if

}//end while

System.out.println(execeed 100 =  "+ sum +" )");
//		   System.out.printf( "Sum is %d\n", sum ); // display sum
//

}               // end main method

}                     // end class calc``````

Well you have not mentioned the problem and just visually going through the code, I am guessing its a compile error caused by a missing double quote on line 47:

``System.out.println(execeed 100 =  "+ sum +" )");``

Should be:-

``System.out.println("execeed 100 =  "+ sum +" )");``

Bro.... i need to display result of sum int by int that keep in by user....right now i just can display all sum...what i need is output like this.....

"( 1+3=4+5=9+66=75+88=163 - the program will terminted cause exceed than 100)

how to do..plz help me...

stephen is correct..

this is simple problem to solve...

Bro.... i need to display result of sum int by int that keep in by user....right now i just can display all sum...what i need is output like this.....

"( 1+3=4+5=9+66=75+88=163 - the program will terminted cause exceed than 100)

how to do..plz help me...

Use an Array to store the numbers keyed in by the User.

it is better to append all integer in stringbuffer while getting as input like this.

stringbuffer sb=new stringbuffer();

sb.append(firstinput+"+");
.
.
.
.
sb.append("="+total);

then convert stringbuffer into string like sb.tostring and display that string..

sys.out.print("the program termintaed because"+sb.toString);

how to use array to store user input bro?....

mmm...still stuck lor......can u guide me to use array ?

mmm...still stuck lor......can u guide me to use array ?

Post the code that you have tried.

as above lor....

``````import java.io.*;
import java.util.Scanner;

public class Soalan1
{
public static void main ( String [] args ) throws IOException   //throw any exceptions
{

//note the previous line. you can write the statements 2 and 3 in a single line
// 2&3. Create a single shared BufferedReader for keyboard input.
int a,n, sum;

final int MAX=100;

sum = 0;

System.out.println( "INSERT INTEGER ! " );

while (true)
{

//	Pembaca read = new Pembaca();

Scanner scan = new Scanner(System.in);

n = scan.nextInt();

// int i = Integer.parseInt( input );

sum = sum + n;

//if (n <=100)
//{

//}
// n++;

//		System.out.println("The total of the numbers is:" + sum);

if (sum  >= 100)
{

// n is zero, so break out of the enclosing while loop
break;

}//end if

//	System.out.println( sum );
//	if (n <=100)
//	{
//	  System.out.print(n);
//  	System.out.print(" + ");
// 	System.out.print(n);
//	System.out.print(" = ");
//  System.out.println(  sum );
//	}
// print out their sum
//	System.out.print(sum);
//	System.out.print(" + ");
//	System.out.print(n);
//	System.out.print(" = ");
//	System.out.println( +sum );
//	sum = sum + n;

// and report our results

}//end while

System.out.println("("+sum+ " exceed 100  =  "+ sum +" terminated)");
//		   System.out.printf( "Sum is %d\n", sum ); // display sum
//

}               // end main method

}                     // end class calc``````

Help me plz...

i need to display like this ( user input + n+ n+n+n+n+n=sum - terminated exceed 100)

I gave you a link on how to use arrays, similarly mustafa gave another solution, I dont see you having tried any of them, If you dont try any of the solutions, how can we help ???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.