Jgrasp program- JAVA please help me with whole program. ive been struggling this
ID: 3617666 • Letter: J
Question
Jgrasp program- JAVAplease help me with whole program. ive been struggling this for 2days ! can anyone help me?
public static SumStack
{
public static void main(String [] args)
{
String A = 5 3 7 3
String B = 3 1 8
System.out.println(Stack<Integer>);
}
public static stack<Integer> Add(Stack<Integer> A,Stack<Integer> B)
Stack<Integer> c = new Stack<Integer>();
int c = 0;
while (!A.isEmpty() && ! B.isEmpty())
{
c = c + A.pop() + B.pop();
C.push(c % 10);
c = c/10;
}
}
That is what my professor wrote the method and i copied and i dontknow how to start in the main, and everything.
he said 3 loops in there.
for example A Stack:
3
7
3
5 (which it means5373)
for B Stack:
8
1
3 (which it means 318)
all altogether 5373 + 318 = 5691
Perform: C = A + B
Display: C
anyone help
? thanks!!!
Explanation / Answer
publicstatic void main(String[]args) { String a= "5373"; String b= "318"; Stack stackA= newStack(); Stack stackB= newStack(); for(char c :a.toCharArray()) { //48 is the ASCII code for '0' stackA.push((int)(c-48)); } for(char c :b.toCharArray()) { stackB.push((int)(c-48)); } // output Stack stackC= add(stackA, stackB); while(!stackC.isEmpty()) { System.out.print(stackC.pop()); } System.out.println(); } _____ FYI you don't need to use JGrasp to compile Javacode, especially when you're not using any speciallibraries.Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.