1. Engineering
  2. Computer Science
  3. i am trying to run a couple of functions in...

Question: i am trying to run a couple of functions in...

Question details

I am trying to run a couple of functions in my main and It won't output anything if there is anything that you see wrong please help me out. I have to use simple, sometimes slower ways because we can use what we haven't learned yet. Here is my code.

package a3;

import java.util.Scanner;

public class LoopsAndImages {

public static void main(String[] args){

String test = "A rabbit has a carrot";

Boolean numbers = hasMoreEvenThanOdd("12344");

System.out.println(test);

System.out.println(hideLetterA(test)+" This is the new string");

System.out.println(numbers);

System.out.println(makeTextTriangle(5));

}

public static String hideLetterA(String sentence) {

Scanner s=new Scanner(sentence);

while(s.hasNext()) {

for(int i=0; i<sentence.length();i++) {

char c=sentence.charAt(i);

int charValue = (int) c;

if(charValue==65 || charValue==97) {

c='*';

}

}

}

s.close();

return sentence;

}

public static Boolean hasMoreEvenThanOdd(String sentence) {

int x=Integer.parseInt(sentence);

if((x%2)==0) {

return true;

}else {

return false;

}

}

public static String makeTextTriangle(int a) {

String stars="";

for(int i=0; i<a; i++) {

for(int j=0; j<i;j++) {

stars="* ";

}

System.out.println();

}

return stars;

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution